/**
 * @Title: PageLinkInterceptor.java
 * @Package　 com.alljk.interceptor
 * @Description: TODO
 * Copyright　Copyright (c) 2015 
 * Company　广州掌控软件有限责任公司
 * @author: sunkxu
 * @date　 2015年3月18日 下午5:17:32
 * @version　V1.0
 */

package com.wyl.interceptor;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * @ClassName: PageLinkInterceptor
 * @Description: TODO
 * @author sunkxu
 * @date 2015年3月18日 下午5:17:32
 */

public class PageLinkInterceptor extends HandlerInterceptorAdapter {
	private ThreadLocal<Boolean> isRepeatSubmit= new ThreadLocal<Boolean>();
	@Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		return super.preHandle(request, response, handler);
    }
	
	@Override  
    public void postHandle(HttpServletRequest request,HttpServletResponse response,Object handler,ModelAndView modelAndView) throws Exception {
		if(HandlerMethod.class.equals(handler.getClass())){
			//获取controller，判断是不是实现登录接口的控制器
			HandlerMethod method = (HandlerMethod) handler;
			Object controller = method.getBean();					
			Map controllerLink = (Map)request.getServletContext().getAttribute("controllerLink");
			Map<String,String> links = (Map)controllerLink.get(controller.getClass().getName());	
			modelAndView.getModelMap().addAttribute("links",links);	
		}
		
		super.postHandle(request, response, handler, modelAndView);
          
    }  
}
